<template>
    <div class="p-class-list">
        <page-title>视频分类列表</page-title>
        <div class="main">
            <div class="search">
                分类名称:<el-input v-model="searchInput" placeholder="请输入分类名称"></el-input>
                <el-button type="primary" @click="querySearch">查询</el-button>
                <el-button class="float-right" @click="$router.push({name:'videoAddClass'})">新增</el-button>
            </div>
            <div class="table">
                <el-table
                    ref="multipleTable" 
                    :data="tableData"
                    border
                    tooltip-effect="dark"
                    style="width: 100%"
                    @selection-change="handleSelectionChange">
                    <el-table-column  align="center" type="selection" width="70"></el-table-column>
                    <el-table-column  align="center" prop="tab_id" label="编号" ></el-table-column>
                    <el-table-column  align="center" prop="title" label="标题" ></el-table-column>
 
                    <el-table-column  align="center" prop="create_time" label="发布时间" width="160" show-overflow-tooltip></el-table-column>
 
                    <el-table-column  align="center" prop="operation" label="操作"  show-overflow-tooltip>
                        <template slot-scope="scope">
                            <!--<el-button @click="lookData(scope.row)" type="text" size="small">查看</el-button>-->
                            <el-button @click="detailData(scope.row)" type="text" size="small">编辑</el-button>
                            <el-button @click="clearData('one',scope.row)" type="text" size="small">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-button  style="margin-top:10px;" @click="clearData('all')">批量删除</el-button>
                <div class="pagination text-center"> 
                    <el-pagination
                        layout="prev, pager, next"
                        :total="count"
                        @current-change="currentChange">
                    </el-pagination>
                </div>
            </div>
            
        </div>
    </div>
</template>

<script>
import * as api from './../../../api/api'
export default {
    data() {
        return{
            searchInput:'',//搜索
            tableData:[ ], //表格列表
            offset:0,
            limit:10,
            count:0,  //总条数
            selectDataList:[],  
        }
    }, 
    created() {
        this.getClassList()
    },    
    methods: {
        getClassList(){
            let vm = this;
            let body={
                model:'Tabs',
                condition:{
                    type:2
                },
                offset:vm.offset,
                limit:vm.limit,
                uid:sessionStorage.getItem('u_id')
            };
            api.getDateList(body).then(res=>{
                if(res.data.code==200){
                    vm.count=parseInt(res.data.data.count); 
                    vm.tableData=res.data.data.data;
                }
            });
        },
        //选择列表
        handleSelectionChange(val) {
            let vm = this;
            val.forEach((item,index)=>{
                vm.selectDataList.push(item.tab_id);
            });
        },
        //删除
        clearData(type,item){  
            let vm = this;
            let arrData=[]; 
            let textInfo='';
            if(type=='all'){
                arrData=vm.selectDataList; 
                textInfo='所选的内容'
            }else{
                arrData.push(item.tab_id);
                textInfo=item.title;
            } 
            vm.$confirm('确定删除'+textInfo, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => { 
                vm.postClear(arrData); 
            });
            
        },
        postClear(arrData){
            let vm = this;
            let body={
                model: "Tabs", 
                update_data: {
                    "is_delete": "1"  //1正常，0删除
                },
                condition: {
                    tab_id: arrData
                }
            };
            api.createBatchData(body).then(res=>{
                if(res.data.code==200){
                    vm.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    vm.getClassList() 
                }
            })
        },
        //编辑
        detailData(item){
            this.$router.push({query:{preTabId:JSON.stringify(item)},name:'videoAddClass'})
        },
        currentChange(e){
            this.offset=(e-1)
            this.getClassList() 
        },
        querySearch(){
           this.getClassList() 
        },
    }, 
}
</script>

<style lang="scss" scoped>
.p-class-list {
    height:100%;  
    .main{
        padding: 10px 50px; 
        
    }
    .search{
        margin-top:10px;
        padding:20px;
        background:#fff;
        .el-input{
            width:200px;
            margin-left:10px;
        }
    }
    .table{
        background:#fff;
        padding:10px 20px;
        .xiangguan{
            font-size:12px !important;
        }
        .pagination{
            margin:25px 0;
        }
    }
}
</style>
